import 'package:f_enjoy_plus/core/constants/app_colors.dart';
import 'package:flutter/material.dart';

class Header extends StatelessWidget implements PreferredSizeWidget {
  final String title;
  final Color backgroundColor;
  final Color textColor;
  final bool centerTitle;
  final List<Widget>? actions;
  final PreferredSizeWidget? bottom;
  final Function? onBack;
  final Widget? leading;
  final bool automaticallyImplyLeading;

  const Header({
    Key? key,
    required this.title,
    this.backgroundColor = AppColors.primary,
    this.textColor = AppColors.white,
    this.centerTitle = true,
    this.actions,
    this.bottom,
    this.onBack,
    this.leading,
    this.automaticallyImplyLeading = true,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return AppBar(
      title: Text(title, style: TextStyle(color: textColor)),
      backgroundColor: backgroundColor,
      centerTitle: centerTitle,
      actions: actions,
      bottom: bottom,
      elevation: 0,
      leading: leading ?? (onBack != null 
        ? IconButton(
            icon: Icon(Icons.arrow_back, color: textColor),
            onPressed: () => onBack!(),
          )
        : null),
      automaticallyImplyLeading: automaticallyImplyLeading,
    );
  }

  @override
  Size get preferredSize => Size.fromHeight(kToolbarHeight + (bottom?.preferredSize.height ?? 0.0));
}